<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.commerceE.domain.User,com.commerceE.domain.Order,com.commerceE.domain.OrderItem,
com.commerceE.domain.Address, com.commerceE.util.DateUtil, com.commerceE.util.Constant, java.util.*"%>
<%@ include file="includes.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<% String basePath = request.getContextPath();%>
<% String baseCSSPath = request.getContextPath()+"/resources/css";%>
<% String baseJSPath = request.getContextPath()+"/resources/js";%>
<% String baseImagePath = request.getContextPath()+"/resources/images";%>

<title>我的订单</title>

<link href="<%=baseImagePath%>/favicon.png" rel="icon">
<link href="<%=baseCSSPath%>/stylesheet.css" rel="stylesheet" type="text/css" >
<script src="<%=baseJSPath %>/jquery-1.js" type="text/javascript" ></script>
<script src="<%=baseJSPath %>/jquery_004.js" type="text/javascript" ></script>
<script src="<%=baseJSPath %>/script.js" type="text/javascript" ></script>
<script src="<%=baseJSPath %>/common.js" type="text/javascript" ></script>
<script src="<%=baseJSPath %>/jquery.validate.min.js" type="text/javascript" ></script>
<script src="<%=baseJSPath %>/jquery.validate.message.js" type="text/javascript" ></script>

<script language="javascript">

function updateQuantityButton(productInstanceId){
	var quantity = document.getElementById("quantity_"+productInstanceId).value;
	if(isNaN(Number(quantity))){
		$('#notification').html('<div class="success" style="display: none;">Please type a valid number!<span><img src="/CommerceFrame/resources/images/close.png" alt="" class="close" /></span></div>');
		$('.success').fadeIn('slow');
		$('#cart-total').html(json['total']);
	}else{
		window.location = "<%=basePath %>/shoppingCart/updateShoppingCartQuantity.html?productInstanceId="+productInstanceId+"&quantity="+quantity;
	}
}

function deleteFromShoppingCart(productInstanceId){
		window.location = "<%=basePath %>/shoppingCart/deleteFromShoppingCart.html?productInstanceId="+productInstanceId;
}

</script>

</head>

<body class="account-login">
	<div class="main-shining">
		
<p style="display: block;" id="back-top"> <a href="#top"><span></span></a> </p>
<div class="row-1">
    <%@ include file="header.jsp" %>
   </div>
<div id="container">
<div id="notification"> </div>
<div id="column-left">
   <%@ include file="navMenu.jsp" %>
 </div>
 
<div id="content">
 
       <div class="breadcrumb">
        <a href="<%=basePath%>"/home.html>首页</a>
        » <a href="<%=basePath%>"/home.html> 我的帐号</a>
        » <a class="last" >我的订单</a>
      </div>
 
      
      
      <%
      
      
List<Order> orderList = null;
if(User.validateCurrentUser(currentUser)){
	orderList = request.getAttribute("orderList")!=null?(List<Order>)(request.getAttribute("orderList")):null;
}else{
	if(currentUser!=null){
		orderList = currentUser.getOrderList();
	}
}


if(orderList==null || orderList.size()==0){
%>
	 <div class="empty">您的订单为空!</div>

<%
}else{
%>	
  <h1>订单列表  </h1> 
    <div class="cart-info"  >
      <div class="shop-cart"  >
      <table width="90%">
        <thead>
          <tr>
            <td align="center" class="name">序号</td>
            <td align="center" class="name">订单号</td>
            <td align="center" class="name" width="150px">商品名称</td>
            <td align="center" class="model" width="70px">发货地址</td>
            <td align="center" class="quantity" width="60px">创建时间</td>
            <td align="center" class="price">是否付款</td>
            <td align="center" class="price">付款方式</td>
            <td align="center" class="price">总金额</td>
            <td align="center" class="price" width="50px">操作</td>
          </tr>
        </thead>
        <tbody>
    <%
	for(int i=0;i<orderList.size();i++){
		Order order = orderList.get(i);
		Address address = order.getAddress();
		String addressStr = address.getStateObject().getProvincename()+", "+address.getCityObject().getCityname()+", "+address.getRoadandstreet() +", "+address.getPostcode();
    %>
          <tr>
           <td class="name"><%=i+1 %>
              </td>
            <td class="name"><%=order.getOrderNo() %>
              </td>
            <td>
              		<%
              			List<OrderItem> orderItemList = order.getOrderItemList();
              			for(int j=0;j<orderItemList.size();j++){
              				OrderItem orderItem  = orderItemList.get(j);
              		%>
              		<a href="<%=basePath %>/product/productDetail.html?productId=<%=orderItem.getProductInstance().getProductId() %>"><%=j+1 %>. <%=orderItem.getProductInstance().getProduct().getProductName() %>, 颜色 : <%=orderItem.getProductInstance().getColor_product_option_value().getDisplayValue() %> 
              		   尺码: <%=orderItem.getProductInstance().getSize_product_option_value().getDisplayValue() %> </a></br>
              		<%		
              			}
              		%>
            </td>
            
            <td class="name"><%=addressStr%>
              </td>
               <td class="name"><%=DateUtil.parseDateToString(order.getCreatedtime(), DateUtil.sdf_bidStatus)%>
              </td>
               <td class="name"><%=order.getPaymentstatus()%>
              </td>
              <td class="name"><%=order.getPaymenttype()==null?'无':order.getPaymenttype()%>
              </td>
            <td class="price">¥<%=order.getOrderprice() %></td>
            
            <td class="price">
            <% 
            if(Constant.PAYMENT_STATUS_UNPAID.equals(order.getPaymentstatus())){
            	%>
            	<a class="button" id="submitOrderId" href="<%=basePath %>/shoppingCart/checkout.html?orderId=<%=order.getOrderid() %>&addressId=<%=order.getAddressId() %>"><span>付款</span></a>
            <% 	
            }else if(Constant.PAYMENT_STATUS_PAID.equals(order.getPaymentstatus())){
            	%>
            	<a class="button" id="submitOrderId" ><span>申请退货</span></a>
            	<% 
            }else if(Constant.PAYMENT_STATUS_RETURNED.equals(order.getPaymentstatus())){
            	%>
            	
            	<% 
            }
            
            %></td>
           
          </tr>
     <%} %>   
          
         </tbody>
      </table>
          </div>
    </div>
   <%} %>
  
  </div>

</div>
<div class="footer-wrap">
	<%@ include file="footer.jsp" %>
</div>
 
</div>
